{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-11-24T00:53:59.505218Z",
     "start_time": "2025-11-24T00:53:59.447629Z"
    }
   },
   "source": [
    "\"\"\"\n",
    "给定某城市一周每天的最高温度Series，完成以下任务:\n",
    "1.找出温度超过30度的天数\n",
    "2.计算平均温度\n",
    "3.将温度从高到低排序\n",
    "4.找出温度变化最大的两天\n",
    "\"\"\"\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "# 给定的温度\n",
    "temperatures = pd.Series([28, 31, 29, 32, 30, 27, 33],\n",
    "                index=['周一', '周二', '周三', '周四', '周五', '周六', '周日'])\n",
    "\n",
    "# 1.找出温度超过30度的天数\n",
    "num = temperatures[temperatures>30].count()\n",
    "print(f\"温度超过30度的天数有：{num}天\")\n",
    "print(\"温度超过30度的天数如下：\")\n",
    "print(temperatures[temperatures>30])\n",
    "\n",
    "# 2.计算平均温度\n",
    "# 3.将温度从高到低排序\n",
    "# 4.找出温度变化最大的两天\n",
    "t3 = temperatures.diff().abs()   # 后 - 前，再求绝对值\n",
    "print(t3)\n",
    "t3.sort_values(ascending=False).keys()  # 降序只显示键的排名"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "温度超过30度的天数有：3天\n",
      "温度超过30度的天数如下：\n",
      "周二    31\n",
      "周四    32\n",
      "周日    33\n",
      "dtype: int64\n",
      "周一    NaN\n",
      "周二    3.0\n",
      "周三    2.0\n",
      "周四    3.0\n",
      "周五    2.0\n",
      "周六    3.0\n",
      "周日    6.0\n",
      "dtype: float64\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Index(['周日', '周二', '周六', '周四', '周三', '周五', '周一'], dtype='object')"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
